var res [][]int
var used map[int]bool

func permuteUnique(nums []int) [][]int {
    res = make([][]int, 0)
    used = make(map[int]bool, 0)
    sort.Ints(nums)
    backTacking(nums, []int{})
    return res
}

func backTacking(nums, path []int) {
    if len(path) == len(nums) {
        tem := make([]int, len(path))
        copy(tem, path)
        res = append(res, tem)
    }
    for i:=0; i<len(nums); i++ {
        if i>0 && nums[i] == nums[i-1] && used[i-1] == true {
            continue
        }
        if used[i] == false {
            path = append(path, nums[i])
            used[i] = true
            backTacking(nums, path)
            path = path[:len(path)-1]
            used[i] = false
        }
    }
}